package com.morty.product.controllor;

import com.morty.product.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = "产品管理API", tags = {"产品管理API"})
@Component
@FeignClient(name = "product", path="/product/product", contextId = "productControllerApi")
public interface ProductControllerApi {

    @ApiOperation(value = "查询产品信息")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "proId", value = "proId", paramType = "path", required = true, dataType = "String")
    )
    @RequestMapping(value = "/getProductById/{proId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ProductVo getProductById(@PathVariable("proId") String proId);

    @ApiOperation(value = "新增")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "productVo", value = "表单数据实体", paramType = "body", required = true, dataType = "ProductVo")
    )
    @PostMapping(value = "/insertProduct", produces = MediaType.APPLICATION_JSON_VALUE)
    public int insertProduct(@Validated @RequestBody ProductVo productVo) throws Exception;

    @ApiOperation(value = "修改")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "productVo", value = "表单数据实体", paramType = "body", required = true, dataType = "ProductVo")
    )
    @PostMapping(value = "/updateProduct", produces = MediaType.APPLICATION_JSON_VALUE)
    public int updateProduct(@Validated @RequestBody ProductVo productVo);

    @ApiOperation(value = "测试seata")
    @PostMapping(value = "/testSeata", produces = MediaType.APPLICATION_JSON_VALUE)
    public String testSeata();

    @ApiOperation(value = "测试seataLock")
    @PostMapping(value = "/testSeataLock", produces = MediaType.APPLICATION_JSON_VALUE)
    public String testSeataLock();

    @ApiOperation(value = "测试分布式锁")
    @PostMapping(value = "/testRedis", produces = MediaType.APPLICATION_JSON_VALUE)
    public String testRedis();

    @ApiOperation(value = "测试分布式锁Util")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "lock", value = "lock", paramType = "path", required = true, dataType = "String")
    )
    @GetMapping(value = "/testRedisUtil/{lock}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String testRedisUtil(@PathVariable("lock") String lock);
}
